<?php if (!defined('THINK_PATH')) exit();?><div class="row">
    <div class="box-header with-border">
        <h4 class="box-title">原订单详情：</h4>
    </div>
    <div class="col-md-3">
        <div class="box box-solid">
            <div class="box-body">
                <ul class="list-unstyled">
                    <li>订单号：<?php echo ($order["order_id"]); ?></li>
                    <li>店铺名称：<?php echo ($order["local_name"]); ?></li>
                    <li>店铺地区：<?php echo ($order["area_text"]); ?></li>
                    <li>店铺地址：<?php echo ($order["addr"]); ?></li>
                </ul>
            </div>
        </div>
    </div>
    <div class="col-md-3">
        <div class="box box-solid">
            <div class="box-body">
                <ul class="list-unstyled">
                    <li>物流公司：<?php echo ($order["logi_name"]); ?></li>
                    <li>物流单号：<?php echo ($order["logi_no"]); ?></li>
                    <li>物流费用：<?php echo ($order["money"]); ?></li>
                    <li>邮编：<?php echo ($order["ship_zip"]); ?></li>
                </ul>
            </div>
        </div>
    </div>
    <div class="col-md-3">
        <div class="box box-solid">
            <div class="box-body">
                <ul class="list-unstyled">

                    <li>订单来源：<?php echo ($order["order_refer"]); ?></li>
                    <li>奖金支付：<?php echo ($order["bonus_pay"]); ?></li>
                    <li>收货地区：<?php echo ($order["ship_area"]); ?></li>
                    <li>收货地址：<?php echo ($order["ship_addr"]); ?></li>
                </ul>
            </div>
        </div>
    </div>
    <div class="col-md-3">
        <div class="box box-solid">
            <div class="box-body">
                <ul class="list-unstyled">
                    <li>收货人：<?php echo ($order["ship_name"]); ?></li>
                    <li>会员：<?php echo ($order["member_id"]); ?></li>
                    <li>手机：<?php echo ($order["ship_mobile"]); ?></li>
                    <li>备注：<?php echo ($order["memo"]); ?></li>
                </ul>
            </div>
        </div>
    </div>
</div>
<div class="row">
    <div class="box-header with-border">
        <h4 class="box-title">订单明细：</h4>
    </div>
    <div class="box-body table-responsive no-padding">
        <table class="table table-hover">
            <tbody>
            <tr>
                <th>物品货号</th>
                <th>物品名称</th>
                <th>数量</th>
                <th>销售价</th>
                <th>实际支付价格</th>
                <th>小计</th>
            </tr>
            <?php if(is_array($list1)): $i = 0; $__LIST__ = $list1;if( count($__LIST__)==0 ) : echo "" ;else: foreach($__LIST__ as $key=>$vo): $mod = ($i % 2 );++$i;?><tr>
                    <td><?php echo ($vo["bn"]); ?></td>
                    <td><?php echo ($vo["name"]); ?></td>
                    <td><?php echo ($vo["nums"]); ?></td>
                    <td><span class="label label-warning"><?php echo ($vo["price"]); ?></span></td>
                    <td><span class="label label-success"><?php echo ($vo["g_price"]); ?></span></td>
                    <td><span class="label label-danger"><?php echo (number_format($vo["amount"], 2, '.', '')); ?></span></td>
                </tr><?php endforeach; endif; else: echo "" ;endif; ?>
            </tbody>
        </table>
    </div>
</div>

<div class="row">
    <div class="box-header with-border">
        <h4 class="box-title">退单明细：</h4>
    </div>
    <div class="box-body table-responsive no-padding">
        <table class="table table-hover">
            <tbody>
            <tr>
                <th>物品货号</th>
                <th>物品名称</th>
                <th>数量</th>
                <th>销售价</th>
                <th>实际支付价格</th>
                <th>小计</th>
            </tr>
            <?php if(is_array($list2)): $i = 0; $__LIST__ = $list2;if( count($__LIST__)==0 ) : echo "" ;else: foreach($__LIST__ as $key=>$vo): $mod = ($i % 2 );++$i;?><tr>
                <td><?php echo ($vo["bn"]); ?></td>
                <td><?php echo ($vo["name"]); ?></td>
                <td><?php echo ($vo["num"]); ?></td>
                <td><span class="label label-warning"><?php echo ($vo["price"]); ?></span></td>
                <td><span class="label label-success"><?php echo ($vo["g_price"]); ?></span></td>
                <td><span class="label label-danger"><?php echo ($vo["xiaoji"]); ?></span></td>
            </tr><?php endforeach; endif; else: echo "" ;endif; ?>
            </tbody>
        </table>
    </div>



    <div class="modal fade" id="show2" tabindex="-1" role="dialog"
         aria-labelledby="myModalLabel" aria-hidden="true">
        <div class="modal-dialog">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close">×
                    </button>
                    <h4 class="modal-title" id="myModalLabel2">
                        确认操作
                    </h4>
                </div>
                <div class="modal-body">
                    <label for="exampleInputprice">确认退款金额(将用于把钱返回用户微信账户)</label>
                    <input class="form-control" type="text" name="price" value="<?php echo ($refund['price']); ?>" id="exampleInputprice">
                    <label for="exampleInputbonus" style="color: red">返还奖金金额（奖金将直接返回到用户账户）</label>
                    <input class="form-control" type="text" name="bonus" value="<?php echo ($refund['bonus']); ?>" id="exampleInputbonus">
                    <div id="valid-price" class="error"></div>
                    <label for="exampleInputEmailbz">备注</label>
                    <textarea class="form-control" rows="2" id="exampleInputEmailbz" placeholder="添加备注" name="desc"></textarea>
                    <input type="hidden" data-dataid="<?php echo ($refund['id']); ?>" data-status="" id="hidden_yu">
                    <?php if($refund['status'] == 2 or $refund['status'] == 4 or $refund['status'] == 5): ?><label for="image" hidden>图片</label>
                        <input class="form-control" type="file" id="image" data-max-file-count="1" hidden/>
                        <input type="hidden" id="image_action"/><?php endif; ?>
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-default close2">
                        关闭
                    </button>
                    <button type="button" class="btn btn-primary mark-submit querentijiao">
                        提交
                    </button>
                </div>
            </div>
        </div>
    </div>
    <script>
        //status 1:门店确认 0:门店取消 4:门店确认收货 5:平台管理员确认打款
        $('#btn2,#btn3,#btn9').on('click',function () {
            var act = $(this).data('action');
            if (act == 'success'){
                $('label[for=exampleInputprice]').show();
                $('#exampleInputprice').show();
                $('#hidden_yu').data('status', '1');
            } else if(act == 'error') {
                $('label[for=exampleInputprice]').hide();
                $('#exampleInputprice').hide();
                $('#hidden_yu').data('status', '0');
            } else if(act == 'shouhuo') {
                $('label[for=exampleInputprice]').show();
                $('#exampleInputprice').show();
                $('#hidden_yu').data('status', '4');
            } else if(act == 'manage') {
                $('label[for=exampleInputprice]').show();
                $('#exampleInputprice').show();
                $('label[for=image]').show();
                $('#image').show();
                $('#hidden_yu').data('status', '5');
            }
            $('#show2').modal('show');
        })
        $('button.close,button.close2').on('click', function () {
            $('#show2').modal('hide');
        })
        $('.querentijiao').on('click', function () {
            var img ='';
            var id = $('#hidden_yu').data('dataid');
            var status = $('#hidden_yu').data('status');
            var find_wl_len = $('#wuliu_name').length;
            var find_wln_len = $('#wuliu_no').length;
            var wuliu_name = '';
            var wuliu_no = '';

            if(find_wl_len > 0 ){
                wuliu_name = $('#wuliu_name').val();
            }
            if(find_wln_len > 0 ){
                wuliu_no = $('#wuliu_no').val();
            }else {
                wuliu_name = '上门退货';
            }




            if (status == '5'){
                img = $('input[name=img]').val();
            }
			var o = $("#exampleInputprice");
			var bonus = $("#exampleInputbonus").val();
			var price = o.val().trim();
			var total_price = parseFloat(price) + parseFloat(bonus);
			var refund_money = <?php echo $refund['price'];?>;
            if (parseFloat(total_price) != parseFloat(refund_money)){
                $("#valid-price").html("退款金额必须等于申请退款金额");
                return;
            }
			if(status == '1' || status == '4' || status == '5'){
				if(mbValidator.isEmpty(price)){
					$("#valid-price").html("请输入退款金额");
					return;
				}else if(isNaN(total_price) || parseFloat(total_price) < 0.01){
					$("#valid-price").html("退款金额必须大于等于0.01");
					return;
				}else{
					mbValidator.fixPrice(o, price);
					price = o.val();
					$("#valid-price").html("");
				}
			}
            var desc = $('textarea[name=desc]').val();
            if (id != '' && status !='') {
                $.ajax({
                    type: "post",
                    url: "<?php echo U('Refund/changeDeliveryFirst');?>",
                    data: {id:id, status:status, desc:desc, price:price,img:img,wuliu_name:wuliu_name,wuliu_no:wuliu_no, bonus:bonus},
                    success: function(msg){
                        alert(msg.message);
                        window.location.reload();
                    },
                    error: function (msg) {
                        alert(msg.message);
                    }
                });
            } else {
                alert('缺少参数');
            }
        })
    </script>
</div>

<style type="text/css">
    .refund-flex-demo{
        display:block;
        padding: 25px;
        height: auto;
        overflow: hidden;
    }
    .refund-flex-demo div{
        float: left;
        width: 33.2%;
        border: 1px solid #dedede;
        border-left: 0;
        min-height: 420px;
        margin-top: 20px;
    }
    .refund-flex-demo div:first-child{
        border-left: 1px solid #dedede;
    }
    .refund-flex-demo div:nth-child(4){
        min-height: 253px;
        border-left: 1px solid #dedede;
    }
    .refund-flex-demo div:nth-child(5){
        min-height: 253px;
    }

    .refund-flex-demo dl{
        margin-bottom: 0;
    }
    .refund-flex-demo dl dt{
        height: 41px;
        line-height: 41px;
        background: #f5f5f5;
        padding: 0 22px;
    }
    .refund-flex-demo dl dd{
        min-height: 41px;
        padding: 0 22px;
        line-height: 41px;
        border-bottom: 1px solid #dedede;
    }
    .refund-flex-demo dl dd:last-child{
        border: none;
    }
    .refund-flex-demo dl dd img{
        width: 30%;
        height: 106px;
        margin-top: 20px;
        margin-left: 10px;
    }
    .refund-flex-demo div:nth-child(5) dl dd img{
        width: 30%;
        height: 80px;
        margin-top: 20px;
        margin-left: 10px;
    }
    .list-unstyled {
        height:84px;
        overflow: auto;
    }

</style>
<!-- 样式模版 -->
<div class="row">
    <div class="refund-flex-demo">
        <div class="">
            <dl>
                <dt>退款（退货）信息</dt>
                <dd>退货单号：<?php echo ($refund["id"]); ?></dd>
                <dd>退货店铺名称：<?php echo ($refund["local_name"]); ?></dd>
                <dd>退货原因：<?php echo ($refund["message"]); ?></dd>
                <dd>用户备注：<?php echo ($refund["comment"]); ?></dd>
                <dd>退货物流公司：<?php echo ($refund["wuliu_name"]); ?></dd>
                <dd>退货物流单号：<?php echo ($refund["wuliu_no"]); ?></dd>
                <?php if($refund['yunfei_price']){ ?>
                <dd>退款运费：<?php echo ($refund["yunfei_price"]); ?></dd>
                <?php } else {?>
                <dd>退款运费：</dd>
                <?php }?>
                <dd>退款金额：<span class="label label-danger"><?php echo ($refund["price"]); ?></span></dd>
                <dd></dd>
            </dl>
        </div>
        <div>
            <dl>
                <dt>退款金额</dt>
                <dd>原订单支付单号：<?php echo ($order["transaction_id"]); ?></dd>
                <dd>退货人：<?php echo ($order["ship_name"]); ?></dd>
                <dd>退货人电话：<?php echo ($order["ship_mobile"]); ?></dd>
                <dd>退货地区：<?php echo ($order["ship_area"]); ?></dd>
                <dd>退货地址：<?php echo ($order["ship_addr"]); ?></dd>
                <?php if(count($refund['store_work_logs']) > 1 && $c = count($refund['store_work_logs'])): ?><dd>生成时间：<?php echo (date('Y-m-d H:i:s',$refund['store_work_logs'][$c-1]['store_confirm_t'])); ?></dd>
                        <dd>操作员：<?php echo ($refund['store_work_logs'][$c-1]['store_user']); ?></dd>
                        <dd>修改后金额：<span class="label label-danger"><?php echo ($refund['store_work_logs'][$c-1]['store_money']); ?></span></dd>
                        <dd>奖金返回金额：<span class="label label-danger"><?php echo ($refund['store_work_logs'][$c-1]['bonus_money']); ?></span></dd>
                        <dd>微信返回金额：<span class="label label-danger"><?php echo ($refund['store_work_logs'][$c-1]['store_money']-$refund['store_work_logs'][$c-1]['bonus_money']); ?></span></dd>
                        <dd>备注：<?php echo ($refund['store_work_logs'][$c-1]['store_memo']); ?></dd><?php endif; ?>
            </dl>
        </div>

        <div>
            <dl>
                <dt>退货附图</dt>
                <dd>
                    <?php if(is_array($refund['images'])): $i = 0; $__LIST__ = $refund['images'];if( count($__LIST__)==0 ) : echo "" ;else: foreach($__LIST__ as $key=>$vo): $mod = ($i % 2 );++$i;?><img src="/Uploads/<?php echo ($vo); ?>" data-bimg="/Uploads/<?php echo ($vo); ?>" onmouseover="GPicEvent.on(this)" onmouseout="GPicEvent.out(this)"><?php endforeach; endif; else: echo "" ;endif; ?>
                </dd>
            </dl>
        </div>
        <?php if(!empty($refund['store_work_logs'])): ?><div>
            <?php if(is_array($refund['store_work_logs'])): $i = 0; $__LIST__ = $refund['store_work_logs'];if( count($__LIST__)==0 ) : echo "" ;else: foreach($__LIST__ as $key=>$vo): $mod = ($i % 2 );++$i;?><dl>
                    <?php if(($i % 2) == 1): ?><dt>门店审核信息</dt><?php endif; ?>
                    <?php if(($i % 2) == 0): ?><dt>门店退货信息</dt><?php endif; ?>
                    <dd>门店审核人：<?php echo ($vo["store_user"]); ?></dd>
                    <dd>门店审核时间：<?php echo (date('Y-m-d H:i:s',$vo["store_confirm_t"])); ?></dd>
                    <dd>门店审核金钱：<span class="label label-danger"><?php echo ($vo["store_money"]); ?></span></dd>
                    <dd>奖金返回金额：<span class="label label-danger"><?php echo ($vo["bonus_money"]); ?></span></dd>
                    <dd>微信返回金额：<span class="label label-danger"><?php echo ($vo['store_money'] - $vo['bonus_money']); ?></span></dd>
                    <dd>门店审核备注：<?php echo ($vo["store_memo"]); ?></dd>
                    <dd></dd>
                </dl><?php endforeach; endif; else: echo "" ;endif; ?>
            </div><?php endif; ?>

        <?php if(!empty($refund['finance_name'])): ?><div>
            <dl>
                <dt>平台审核信息</dt>
                <dd>审核人：<?php echo ($refund["finance_name"]); ?></dd>
                <dd>审核时间：<?php echo (date('Y-m-d H:i:s',$refund["finance_confirm_t"])); ?></dd>
                <dd>审核金钱：<span class="label label-danger"><?php echo ($refund["price_detail"]); ?></span></dd>
                <dd>审核备注：<?php echo ($refund["finance_memo"]); ?></dd>
                <dd>奖金返回金额：<span class="label label-danger"><?php echo ($refund["refund_bonus"]); ?></span></dd>
                <dd>微信返回金额：<span class="label label-danger"><?php echo ($refund['price_detail'] - $refund['refund_bonus']); ?></span></dd>
                <dd>退货单号：<?php echo ($refund["id"]); ?></dd>
            </dl>
        </div><?php endif; ?>
        <?php if(!empty($refund['finance_img'])): ?><div>
            <dl>
                <dt>财务返款信息</dt>
                <dd><span>返款附图</span>
                    <?php if($refund['finance_img'] != ''): ?><img src="/Uploads/<?php echo ($refund["finance_img"]); ?>" data-bimg="/Uploads/<?php echo ($refund["finance_img"]); ?>" onmouseover="GPicEvent.on(this)" onmouseout="GPicEvent.out(this)"/><?php endif; ?>
                </dd>
            </dl>
        </div><?php endif; ?>
    </div>
</div>

<?php if($refund['status'] == '1'){ ?>
<button class="btn btn-primary" data-toggle='modal' id="btn2" data-action="success">初审通过</button>
<button class="btn btn-danger" data-toggle='modal' id="btn3" data-action="error">初审失败</button>
<?php } elseif(($refund['status'] == '3' || $refund['status'] == '2') && $refund['type'] == '3' ) { ?>
<button class="btn btn-primary" data-toggle='modal' id="btn2" data-action="shouhuo">确认收货</button>

<select class="selector" style="margin-left: 10px;">
    <option value="1"  >上门退货</option>
    <option value="2" <?php if($refund['wuliu_no'] != ''): ?>selected<?php endif; ?>>物流快递</option>
</select>
<div class="isWs <?php if($refund['wuliu_no'] == ''): ?>hide<?php endif; ?> " style=" position: absolute; left: 15%;bottom: 20px;">
    <?php if($refund['wuliu_no'] != ''): ?><div class="islistwl">
    物流公司：<input type='text' id='wuliu_name' name='wuliu_name' value="<?php echo ($refund['wuliu_name']); ?>" placeholder='圆通快递'>
    物流单号：<input type='text'  id='wuliu_no' name='wuliu_no' value="<?php echo ($refund['wuliu_no']); ?>" placeholder='1233217891'>
        </div><?php endif; ?>
</div>
<?php } elseif($refund['status'] == '0') { ?>
<button class="btn btn-danger" data-toggle='modal' id="btn0" data-action="error">该退单已被取消了</button>
<?php } elseif($refund['status'] == '6') { ?>
<button class="btn btn-danger" data-toggle='modal' id="btn0" data-action="error">用户重新申请</button>
<?php } elseif($refund['status'] == '7') { ?>
<button class="btn btn-danger" data-toggle='modal' id="btn0" data-action="error">用户取消申请</button>
<?php } elseif($refund['status'] == '5') { ?>
<button class="btn btn-success" data-toggle='modal' id="btn0" data-action="success">退货退款完成</button>
<?php } elseif( ($refund['status'] == '2' && $refund['type'] != '3') || ($refund['status'] == '4' && $refund['type'] == '3') ) { ?>
    <?php if(strtolower(MODULE_NAME) == 'manage'){ ?>
    <button class="btn btn-primary" data-toggle='modal' id="btn9" data-action="manage">审核</button>
    <?php }elseif (strtolower(MODULE_NAME) == 'admin'){ ?>
    <button class="btn btn-primary" data-toggle='modal' id="btn0" data-action="success">等待平台处理中</button>
    <?php } ?>
<?php } ?>


<link rel="stylesheet" href="/Public/admin/fileinput/fileinput.min.css">
<script src="/Public/admin/fileinput/fileinput.min.js"></script>
<script>
    /*冉 3-10*/
    $(".selector").on('change',function () {
        $_this =$(this);
        if($_this.val() == 1){
            $('.islistwl').remove();
        }
        if($_this.val() == 2){
            $('.isWs ').removeClass('hide');
            $('.isWs').html(" <div class='islistwl'>物流公司：<input type='text' id='wuliu_name' name='wuliu_name' value=\"<?php echo ($refund['wuliu_name']); ?>\" placeholder='圆通快递'>" +
                    "物流单号：<input type='text'  id='wuliu_no' name='wuliu_no' value=\"<?php echo ($refund['wuliu_no']); ?>\" placeholder='1233217891'></div>");
        }



    });

    /*************************/
    // 上传图片js
    $("#image").fileinput({
                overwriteInitial: true,
                dropZoneEnabled: false,
                uploadUrl: '/admin/upload/index/"',
                language: 'zh',
                showRemove: false,
                maxFileCount: 1,
                browseClass: 'btn btn-primary btn-docup',
                showPreview: true,
                uploadClass: 'btn btn-default btn-docup',
                allowedFileTypes: ["image"],
                browseLabel: "添加图片",
                uploadLabel: "上传图片",
                initialCaption:"<?php echo ($carousel['img']); ?>",
            <?php if((!empty($carousel['img']))): ?>initialPreview:['<img src="/Uploads/<?php echo ($carousel[img]); ?>" class="file-preview-image">']<?php endif; ?>
    }).on("fileuploaded", function (event, data, previewId, index) {
        var response = data.response;
        if (data.jqXHR.status == 200) {
            // ajax 成功返回数据写入
            $('.file-preview-frame').eq(index).append("<input class='abc' type='hidden' name='img' value='"+response+"'>");
        }
    });
    $("#image").on('filecleared', function(event) {
        $("#image_action").val(1);
    });
</script>